package com.design.strategy.singleton;


import java.util.ArrayList;
import java.util.List;

/**
 * 原型和单例是冲突，不能同时存在
 *
 * @author: cong zhi
 * @createDate: 2022/5/8 18:34
 * @updateUser: cong zhi
 * @updateDate: 2022/5/8 18:34
 * @updateRemark: 修改内容
 * @version: v1.0
 */
public class Client {

    public static void main(String[] args) {
        // 创建对象
        ConcretePrototype prototype = ConcretePrototype.getInstance();
        prototype.setAge(19);
        prototype.setName("lisa");
        // List 属于引用类型
        List<String> hobbies = new ArrayList<>();
        hobbies.add("书法");
        hobbies.add("健身");
        prototype.setHobbies(hobbies);


        //拷贝对象
        ConcretePrototype cloneType = prototype.clone();
        cloneType.getHobbies().add("技术控");
        System.out.println("克隆对象:" + cloneType);
        System.out.println("原型对象:" + prototype);
        System.out.println(cloneType == prototype);

        System.out.println("克隆对象爱好:" + cloneType.getHobbies());
        System.out.println("原型对象爱好:" + prototype.getHobbies());
        System.out.println(cloneType.getHobbies() == prototype.getHobbies());

    }
}
